<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>
<body>
    
</body>
<script>
    // 1. 截取字符串中的"中华"
const str1 = "我爱中华人民共和国";
console.log(str1.substring(2, 4));
</script>
<script>
    // 2. 查找字符串中所有o出现的位置
const str2 = "abcoefoxyozzopp";
let positions = [];
let index = str2.indexOf('o');
while (index !== -1) {
    positions.push(index);
    index = str2.indexOf('o', index + 1);
}
console.log("o出现的位置:", positions); 
</script>
<script>
    // 3. 把字符串中所有的o替换成!
const str3 = "abcoefoxyozzopp";
console.log(str3.replace(/o/g, '!')); 
</script>
<script>
    // 4. 判断一个字符串中出现次数最多的字符及其次数
const str4 = "abcoefoxyozzopp";
const charMap = {};
let maxCount = 0;
let maxChar = '';

for (const char of str4) {
    charMap[char] = charMap[char] + 1 || 1;
    if (charMap[char] > maxCount) {
        maxCount = charMap[char];
        maxChar = char;
    }
}

console.log(`出现次数最多的字符是'${maxChar}'，出现了${maxCount}次`);    
</script>
</html>